package cn.intotw.rdcj.task.controller;


import cn.intotw.rdcj.core.bean.Result;
import cn.intotw.rdcj.task.bean.dto.BookContentBookQueryDto;
import cn.intotw.rdcj.task.bean.dto.BookListBookQueryDto;
import cn.intotw.rdcj.core.bean.DataResponse;
import cn.intotw.rdcj.core.constant.Constants;
import cn.intotw.rdcj.task.bean.dto.BookSectionsBookQueryDto;
import cn.intotw.rdcj.task.bean.vo.BookListQueryVo;
import cn.intotw.rdcj.task.bean.vo.BookSectionsQueryVo;
import cn.intotw.rdcj.task.service.RdcjBookServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author Chenxiang
 * @Description: 数据查询
 * @create 2020/4/9 11:02
 */
@RestController
@RequestMapping("/book")
@Api(value = "/book", tags = {"bookTag"}, description = "书籍Controller接口类")
@Slf4j
public class RdcjBookQueryController {
    @Autowired
    @Qualifier("rdcjBookService")
    private RdcjBookServiceImpl rdcjBookService;

    /**
     * @param bookListQueryDto {@link BookListBookQueryDto}
     * @param source           书籍源，请求头中获得
     * @return {@link BookListQueryVo}
     * @author Chenxiang
     * @date 2020/7/31 14:42
     **/
    @PostMapping("/v1/queryBook")
    @ApiOperation(value = "Api-查询指定书籍", notes = "Api-查询指定书籍")
    public ModelAndView queryBook(@RequestBody @Valid @ApiParam(name = "用户信息", value = "传入json格式",
            required = true, type = "application/json") BookListBookQueryDto bookListQueryDto,
                                  @RequestHeader String source) throws Exception {
        log.info("/book/v1/query,request={}", bookListQueryDto);
        List<BookListQueryVo> listResult = rdcjBookService.queryBook(bookListQueryDto);
        return new ModelAndView(Constants.JSON_DATA_VIEW, DataResponse.successWithResult(listResult));
    }

    @ApiOperation(value = "Api-查询指定书籍", notes = "Api-查询指定书籍")
    @PostMapping("/v1/querySections")
    public ModelAndView querySections(@RequestBody @Valid @ApiParam(name = "用户信息", value = "传入json格式",
            required = true) BookSectionsBookQueryDto bookListQueryDto,
                                      @RequestHeader String source) throws Exception {
        log.info("/book/v1/querySections,request={}", bookListQueryDto);

        List<BookSectionsQueryVo> listResult = rdcjBookService.querySections(bookListQueryDto);
        return new ModelAndView(Constants.JSON_DATA_VIEW, DataResponse.successWithResult(null));
    }

    @ApiOperation(value = "Api-查询指定书籍", notes = "Api-查询指定书籍")
    @PostMapping("/v1/queryContent")
    public ModelAndView queryContent(@RequestBody @Valid @ApiParam(name = "用户信息", value = "传入json格式",
            required = true) BookContentBookQueryDto bookListQueryDto) {
        log.info("/book/v1/querySections,request={}", bookListQueryDto);


        return new ModelAndView(Constants.JSON_DATA_VIEW, DataResponse.successWithResult(null));
    }
}